<template>
	<div class="page">
		<h1>API文档</h1>
		<el-table :data="tableData.rows" border style="width: 100%">
			<el-table-column prop="interfaceName" label="接口名称" width="250">
			</el-table-column>
			<el-table-column prop="interfacePrefix" label="应用密钥">
			</el-table-column>
			<el-table-column prop="interfaceUrl" label="url"> </el-table-column>
			<el-table-column label="操作">
				<template #default="scope">
					<el-button @click="goDetail(scope.row)" type="text"> 详情 </el-button>
				</template>
			</el-table-column>
		</el-table>
	</div>
</template>
<script setup>
import request from "@/utils/request.js";
import { onMounted, reactive, ref } from "vue";

let tableData = reactive({
	rows: [],
	total: 0,
	pageNum: 1,
	pageSize: 10,
	appName: "",
});
onMounted(() => {
	getApiList();
});
const getApiList = async () => {
	let res = await request({
		url: "/user/interface/list",
		method: "post",
		data: {
			pageNum: 1,
			pageSize: 10,
		},
	});
	if (res.code == 200) {
		tableData.rows = res.rows;
		tableData.total = res.total;
	}
};
const goDetail = async (row) => {
	console.log(row);
	let res = await request({
		url: "/user/interface/list",
		method: "get",
		data: {
			pageNum: 1,
			pageSize: 10,
		},
	});
};
const arr = [
	{
		id: "bdd737d6-26d8-4e72-80ff-ff38941273e7",
		name: "supplier_address",
		type: "8",
		length: "",
		required: "true",
		parentName: "0",
		exampleValue: "1111",
		chineseDesc:
			"工厂仓库出货地址/供应商仓库发货地址或上门提货地址。请根据参数（is_pickup）选择是否上门提货类型选择进行填写。",
		englishDesc:
			"Factory warehouse shipping address/supplier warehouse shipping address. Pickup address . please select the pickup type according to the parameters (is_pickup).",
		remark: "",
		remarkEn: "",
	},
	{
		id: "74c8705c-6682-4277-bd84-bde90684d33a",
		pid: "bdd737d6-26d8-4e72-80ff-ff38941273e7",
		name: "supplier_address.country",
		type: "1",
		length: "2",
		required: "true",
		parentName: "supplier_address",
		exampleValue: "CN",
		chineseDesc: "国家;国家二字码，详细参考国际二字码。如：CN（中国）",
		englishDesc:
			"Countries; Country code, refer to international code in detail. Such as: CN (China)",
		remark: "",
		remarkEn: "",
	},
	{
		id: "992c35d2-9aae-405d-a940-741a85899ec3",
		pid: "bdd737d6-26d8-4e72-80ff-ff38941273e7",
		name: "supplier_address.state",
		type: "1",
		length: "64",
		required: "false",
		parentName: "supplier_address",
		exampleValue: "广东省",
		chineseDesc: "州/省 ; 如 ：广东省",
		englishDesc: "State/province. Guangdong province",
		remark: "",
		remarkEn: "",
	},
	{
		id: "559de739-4d55-4ab0-8857-577b4295e0dd",
		pid: "bdd737d6-26d8-4e72-80ff-ff38941273e7",
		name: "supplier_address.city",
		type: "1",
		length: "64",
		required: "false",
		parentName: "supplier_address",
		exampleValue: "深圳市",
		chineseDesc: "城市 ; 如 ：深圳市",
		englishDesc: "City; For example, shenzhen",
		remark: "",
		remarkEn: "",
	},
	{
		id: "83890ae0-3d32-4915-9c30-5beba56004db",
		pid: "bdd737d6-26d8-4e72-80ff-ff38941273e7",
		name: "supplier_address.district",
		type: "1",
		length: "64",
		required: "false",
		parentName: "supplier_address",
		exampleValue: "宝安区",
		chineseDesc: "区/县 ; 如 ：宝安区",
		englishDesc: "The district/county; For example: bao 'an district",
		remark: "",
		remarkEn: "",
	},
	{
		id: "3417ac5f-97c4-44ab-9bae-148f2412abf3",
		pid: "bdd737d6-26d8-4e72-80ff-ff38941273e7",
		name: "supplier_address.post_code",
		type: "1",
		length: "64",
		required: "false",
		parentName: "supplier_address",
		exampleValue: "518000",
		chineseDesc: "邮编 ; 如 ：518000",
		englishDesc: "Zip code; Such as: 518000",
		remark: "",
		remarkEn: "",
	},
	{
		id: "5b26ed8c-ef80-456d-ba32-6250301c431b",
		pid: "bdd737d6-26d8-4e72-80ff-ff38941273e7",
		name: "supplier_address.street",
		type: "1",
		length: "256",
		required: "false",
		parentName: "supplier_address",
		exampleValue: "西乡街道西乡宝源路",
		chineseDesc: "街道/详细地址 ; 如：西乡街道西乡宝源路",
		englishDesc:
			"Street/detailed address; For example: xixiang street xixiang baoyuan road",
		remark: "",
		remarkEn: "",
	},
	{
		id: "5b26ed8c-ef80-456d-ba32-6250301c431b",
		pid: "bdd737d6-26d8-4e72-80ff-ff38941273e7",
		name: "supplier_address.street",
		type: "1",
		length: "256",
		required: "false",
		parentName: "supplier_address.a",
		exampleValue: "aaaaa",
		chineseDesc: "街道/详细地址 ; 如：西乡街道西乡宝源路",
		englishDesc:
			"Street/detailed address; For example: xixiang street xixiang baoyuan road",
		remark: "",
		remarkEn: "",
	},
];
let apiObj = {};
let num = 0;
const toKeys = (obj, arr, value) => {
	num++;
	let splitArr = arr.split(".");
	// ['supplier_address', 'country']
	if (splitArr.length > 1) {
		if (!(obj[splitArr[0]] instanceof Object)) {
			obj[splitArr[0]] = {};
		}
		toKeys(obj[splitArr[0]], splitArr.slice(1).join("."), value);
	} else {
		obj[splitArr[0]] = value;
	}


};
arr.forEach((item) => {
	toKeys(apiObj, item.name, item.exampleValue);
});
console.log("apiObj", apiObj);
</script>
